using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class PlayerPriAtkState : PlayerState
{
    private int comboCounter = 1;       

    private float lastTimeAttack;       
    private float comboWindows = 2;         

    private float specialKeyTimer;
    private float specialSwithTime = 0.2f;

    public PlayerPriAtkState(Player _player, PlayerStateMachine _playerStateMachine, string _animBoolName) : base(_player, _playerStateMachine, _animBoolName)
    {
    }

    public override void Enter()
    {
        base.Enter();

        //AudionManager.instance.PlaySFX(2, null);

        //player.anim.SetBool(player.currentWeaponName, true);

        xInput = 0;

        if (comboCounter > 3 || Time.time > lastTimeAttack + comboWindows)
        {
            comboCounter = 1;
        }

        player.anim.SetInteger("ComboCounter", comboCounter);

        #region    AttackDirSet
        float attackDir = player.facingDir;

        if (xInput != 0)
        {
            attackDir = xInput;
        }
        #endregion

        player.SetVelocity(player.attackMovement[comboCounter - 1] * attackDir, rb.velocity.y);
    }

    public override void Exit()
    {
        base.Exit();

        player.StartCoroutine("BusyFor", .15f);

        comboCounter++;
        lastTimeAttack = Time.time;

        stateTimer = .1f;

        //player.anim.SetBool(player.currentWeaponName, false);
    }

    public override void Update()
    {
        base.Update();

        if (stateTimer < 0)
            rb.velocity = new Vector2(0, 0);

        //if (comboCounter == GetMaxCombo() && Input.GetKey(KeyCode.K))
        //{
        //    specialKeyTimer += Time.deltaTime;
        //    if (specialKeyTimer > specialSwithTime)
        //    {
        //        player.stateMachine.ChangeState(player.specialAtkState);
        //    }
        //}

        if (triggerCalled)
            stateMachine.ChangeState(player.idleState);
    }

    private int GetMaxCombo()
    {
        //if (player.currentWeaponName == "Sword") return 3;
        //else if (player.currentWeaponName == "Scikle") return 2;

        return 0;
    }
}
